@extends('admin.layout.ucommon')

@section('css')
    <link rel="stylesheet" href="{{asset('static')}}/select2/select2.css">
    <link rel="stylesheet" href="{{asset('webuploader')}}/webuploader.css">
@endsection

@section('content')
    <div class="wrapper wrapper-content animated fadeIn">
        <div class="ibox-content" id="app">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <form action="{{route('admin.article.store')}}"  class="form-horizontal" role="form"  id="form-node-add" method="post" enctype="multipart/form-data">
                        @csrf
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label"><span class="text-danger">*</span>文章标题:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="title" name="title"  autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="description" class="col-sm-2 control-label">文章描述:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="description" name="description"  autocomplete="off">
                            </div>
                        </div>
{{--                        <div class="form-group">--}}
{{--                            <label for="pic" class="col-sm-2 control-label">文章封面:</label>--}}
{{--                            <div class="col-sm-10">--}}
{{--                                <input type="file" class="form-control" id="pic" name="pic" >--}}
{{--                            </div>--}}
{{--                        </div>--}}
                        <div class="form-group">
                            <label for="pic" class="col-sm-2 control-label">文章封面:</label>
                            <div class="col-sm-10">
                                <input type="hidden" id="pic">
                                <div id="picker">上传文章封面</div>
                                <div>
                                    <img src="" alt="" id="img">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label">文章内容:</label>
                            <div class="col-sm-10">
                                <textarea name="body" id="container"  ></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn  btn-success">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection


@section('js')
    <script type="text/javascript" src="{{asset('static')}}/jquery-validate/dist/jquery.validate.min.js"></script>
    <script type="text/javascript" src="{{asset('static')}}/jquery-validate/dist/localization/messages_zh.js"></script>
    <script src="{{asset('static')}}/layer/layer.js"></script>
    <script type="text/javascript" src="{{asset('static')}}/vue/vue.js"></script>
    <!--webuploader-->
    <script type="text/javascript" src="{{asset('webuploader')}}/webuploader.js"></script>

    <!-- 配置文件 -->
    <script type="text/javascript" src="{{asset('static')}}/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="{{asset('static')}}/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('container',{
            initialFrameHeight:600,
        });
    </script>
    <script>
        var uploader = WebUploader.create({

            // swf文件路径
            swf:  '/webuploader/Uploader.swf',

            // 文件接收服务端。
            server: '{{route('admin.article.upfile')}}',
            formData:{
              _token:'{{csrf_token()}}'
            },
            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: {
                id:'#picker',
                multiple:false
            },

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: true
        });

        uploader.on('uploadSuccess',function(file,ret){
           //图片路径
           let src=ret.url;
           //给表单添加value值
            $("#pic").val(src);
            //给图片添加src
            $("#img").attr('src',src);
       });


        //异步变同步
        async function delArticle(evt,obj){
            evt.preventDefault();
            //请求的URL地址
            let url = $(obj).attr('href');
            //发起ajax
            let ret = await  fetch(url,{
                methond:'delete',
                headers:{
                    'X-CSRF-TOKEN':'{{csrf_token()}}'
                }
            });
            let json = await ret.json();

            //取消默认行为
            return false;

        }


    </script>
@endsection
